(function() {
  var utils;

  utils = {
    cutStringByViewSize: function(str, viewSize) {
      var charCode, currentViewSize, index, strLength;
      strLength = str.length;
      viewSize *= 2;
      currentViewSize = 0;
      index = 0;
      while (index !== strLength) {
        charCode = str.charCodeAt(index);
        if (charCode < 0xff) {
          currentViewSize++;
        } else {
          currentViewSize += 2;
        }
        index++;
        if (currentViewSize > viewSize) {
          break;
        }
      }
      if (index === strLength) {
        return str;
      } else {
        return str.substring(0, index) + '...';
      }
    }
  };

  module.exports = utils;

}).call(this);
